import subprocess
import os
import shutil


def run_build():
    # Ensure the build directory exists
    # build_dir = os.path.join(os.path.dirname(__file__), "build")
    # if not os.path.exists(build_dir):
    #     os.makedirs(build_dir)

    # icon_path = os.path.join(os.path.dirname(__file__), "icon.ico")
    # assert os.path.exists(icon_path), "Icon file not found"

    # Run PyInstaller
    # subprocess.check_call(
    #     [
    #         "pyinstaller",
    #         "--onefile",
    #         "--clean",
    #         "--noconsole",
    #         "--distpath",
    #         build_dir,
    #         "--icon",
    #         icon_path,
    #         "--name",
    #         "发票信息提取工具",
    #         "main.py",
    #     ]
    # )

    # Copy the icon file to the build directory
    # shutil.copy(icon_path, os.path.join(build_dir, "icon.ico"))

    # Remove spec file
    # spec_file = os.path.join(build_dir, "发票信息提取工具.spec")
    # if os.path.exists(spec_file):
    #     os.remove(spec_file)

    # Run PyInstaller with the spec file
    spec_path = os.path.join(os.path.dirname(__file__), "build.spec")
    subprocess.check_call(
        [
            "pyinstaller",
            spec_path,
        ]
    )


if __name__ == "__main__":
    run_build()
